package bookez.model.dao.hibernate;

import java.util.List;

import org.hibernate.Query;

import bookez.model.businessobject.BusType;
import bookez.model.dao.BusTypeDao;
import bookez.model.dao.generic.GenericDaoHibernateImpl;
import bookez.model.exception.DataAccessLayerException;

public class BusTypeDaoHibernateImpl extends GenericDaoHibernateImpl<BusType, Long> implements BusTypeDao {

	public BusTypeDaoHibernateImpl(Class<BusType> type) {
		super(type);
		// TODO Auto-generated constructor stub
	}//end constructor

	@SuppressWarnings("unchecked")
	@Override
	public List<BusType> findAll() throws DataAccessLayerException {
		// TODO Auto-generated method stub
		List<BusType> result = null;
		
		try {
			Query query = getSession().getNamedQuery( BusType.NamedQueries.FIND_ALL );
			result = query.list();
		}//end try
		
		catch ( Exception ex ) {
			throw new DataAccessLayerException( ex );
		}//end catch Exception
		
		return result;
	}//end method findAll

	@Override
	public BusType findByName(String name)
			throws DataAccessLayerException {
		// TODO Auto-generated method stub
		BusType result = null;
		
		try {
			Query query = getSession().getNamedQuery( BusType.NamedQueries.FIND_BY_NAME );
			query.setParameter( "name", name );
			
			result = (BusType)query.uniqueResult();
		}//end try
		
		catch ( Exception ex ) {
			throw new DataAccessLayerException( ex );
		}//end catch Exception
		
		return result;
	}//end method findByName

}//end class BusTypeDaoHibernateImpl
